﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

namespace HideComments
{
    public partial class HideCommentsOptions : Form
    {
        private Dictionary<string, CommentColor> m_CommentColors;

        public HideCommentsOptions(Dictionary<string, CommentColor> commentColors)
        {
            InitializeComponent();

            m_CommentColors = commentColors;
            FillListView();
        }

        private void FillListView()
        {
            foreach (var item in m_CommentColors)
            {
                ListViewItem lvi = new ListViewItem(item.Key);
                lvi.Checked = item.Value.Active;
                listView1.Items.Add(lvi);
            }
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);

            System.Configuration.Configuration config =
                System.Configuration.ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);

            foreach (ListViewItem item in listView1.Items)
            {
                config.AppSettings.Settings[item.Text].Value = item.Checked.ToString();
                m_CommentColors[item.Text].Active = item.Checked;
            }

            config.Save();
            System.Configuration.ConfigurationManager.RefreshSection("appSettings");
        }
    }
}
